-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle non-Error objects thrown as error gracefully, still attempt to report them in a useful way #232
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to fixing this yourself, overall i agree that it could be useful to be able to notify
different kind of objects.
I choose to force it to be an error because we got few case before when error where not saved because of the wrong data structure which is hard to understand for customers generally.
… limit for those errors' messages, increase robustness against weird values
I will release this tomorrow under the 4.1.0 tag, thanks again for taking the time to change this ! |
Some code (unfortunately) throws things that are not
Error
objects. The things thrown may be raw data returned from an API, plain objects, strings, in the worst case evennull
orundefined
.While
notifyError
did already reject things that were notError
objects, the other handlers (uncaught exception, unhandled rejection, Express/Koa middlewares) did not.I think that
a) The behavior should be the same regardless which handler handles the error
b) Things that are not
Error
objects should still be reported in the most meaningful way (i.e. giving the developer enough information to understand what the error actually was).Therefore, I modified the behavior so that things other than
Error
s are simply converted to anError
with the JSON representation of the old data asmessage
.Even though the stack of those errors is then meaningless, the JSON data should give the developer enough information, definitely more than not seeing the error at all (old behavior of
notifyError
), getting no description of the error (old behavior of the other handlers, sinceerr.message
may simply be undefined) or crashing in a weird way (old behavior of the other handlers in the case that the error wasnull
orundefined
).